﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace XqWebSite
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)//判断是否回发
            {
                if (Request["ID"] != null)//判断是否有参数传入
                {
                    InitData();//执行初始化函数
                }
            }
        }
        protected void InitData()
        {
            string id = Request["ID"].ToString();
            try
            {
                string SQL = "select * from Admin where ID='" + id + "'";
                DataTable dt = DBHelper.GetDataSet(SQL).Tables[0];//获取对应的参数并且对页面进行绑定
                if (dt.Rows.Count > 0)
                {
                    this.Tex_username.Text = dt.Rows[0]["UserName"].ToString();
                    this.Tex_password.Text = dt.Rows[0]["PassWord"].ToString();
                }
            }
            catch
            {
            }
        }

        protected void Menu2_MenuItemClick(object sender, MenuEventArgs e)
        {

        }

        protected void Btn_qd_Click(object sender, EventArgs e)
        {
           string SQL = "";
           bool iRet=false;
           if (Request["ID"] != null)//判断是否有参数
           {
               string id = Request["ID"].ToString();
               SQL=  "update Admin set UserName='"+Tex_username.Text+"',PassWord='"+Tex_password.Text+"' where ID='" + id + "'";//执行更新操作
               iRet = DBHelper.ExecSql(SQL);
           }
           else
           {
               SQL= "insert into Admin(UserName,PassWord)values('"+Tex_username.Text+"','"+Tex_password.Text+ "')";;//执行添加操作
               iRet = DBHelper.ExecSql(SQL);
           }
            if (iRet)
            {
                DBHelper.ShowMessage(Page, "恭喜您，操作成功！","");
                Tex_username.Text = "";
                Tex_password.Text = "";
            }
            else
            {
                DBHelper.ShowMessage(Page, "对不起，操作失败！","");
            }
        }

        protected void Btn_qx_Click(object sender, EventArgs e)
        {
            Tex_username.Text ="";
            Tex_password.Text ="";
        }
    }
}